<?php
require_once 'PHPUnit/Framework.php';

require_once(dirname(__FILE__).'/../../libraries/UCLibPDOFactory.php');
require_once(dirname(__FILE__).'/../../libraries/UCLibLogger.php');  

function  tagname2dbconfig($tagname){
    return array(
        'driver' => 'mysql',
        'host' => '127.0.0.1',
        'port' => '3306',
        'username' => 'root',
        'password' => '',
        'database' => 'test',
        'table' => 'test'
    );
}

class UCLibPDOFactoryTest extends PHPUnit_Framework_TestCase {
    private $_rmod;
    
    protected function setUp()
    {
        UCLibLogger::attach(new StdoutLogOb());    
        $this->_pdo = UCLibPDOFactory::getPDO('tagname2dbconfig','aa');
    }
    
    protected function tearDown()
    {
        
    }
    
    function test_query_one_with_prepare()
    {
        $ret = $this->_pdo->query_one_with_prepare('select field1 from test.test');
        UCLibLogger::debug($ret);
        $this->assertTrue( (false!==$ret), $ret, print_r($this->_pdo->errorInfo(),true));
        
        $ret = $this->_pdo->query_one_with_prepare('select count(1) as num from test.test2');
        //UCLibLogger::debug($ret);
        $this->assertTrue( (false!==$ret), $ret, print_r($this->_pdo->errorInfo(),true));
        
        $ret = $this->_pdo->query_one_with_prepare('select f5 as num from test.test2');
        //UCLibLogger::debug($ret);
        $this->assertTrue( (false===$ret), print_r($this->_pdo->errorInfo(),true));
        
    }
    function test_query_one_row_with_prepare()
    {
        $ret = $this->_pdo->query_one_row_with_prepare('select count(1) as num from test.test2');
        //UCLibLogger::debug($ret);
        $this->assertTrue( (false!==$ret), $ret, print_r($this->_pdo->errorInfo(),true));
        
        $ret = $this->_pdo->query_one_row_with_prepare('select f1 as num from test.test2');
        //UCLibLogger::debug($ret);
        $this->assertTrue( (false!==$ret), print_r($this->_pdo->errorInfo(),true));
        
        $ret = $this->_pdo->query_one_row_with_prepare('select f5 as num from test.test2');
        //UCLibLogger::debug($ret);
        $this->assertTrue( (false===$ret), print_r($this->_pdo->errorInfo(),true));
        
    }
    
    
}


?>